<?php

namespace App\Common\Lib\Com\Kafka;

use App\Common as com;
use App\Common\Lib\Com\Kafka\PrepareConsumer as thisPrepareConsumer;
use App\Common\Lib\Com\Kafka as nameKafka;
use longlang\phpkafka\Consumer\Consumer as kafkaConsumer;
use longlang\phpkafka\Consumer\ConsumerConfig;
use longlang\phpkafka\Consumer\ConsumeMessage;

class PrepareConsumer extends ConsumerConfig {

	use com\Cla\ClaBase\Traits\Make;

	public function connectConsumer():nameKafka\Consumer {
		return nameKafka\Consumer::makeOfNew( $this );
	}

	public function setGroupIdOfRand(  ):self {
		return $this->setGroupId( uniqid( '', false ) );
	}

	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @return static
	 */
	public static function newOfDefault():self {
		$config = self::make();
		$config->setBroker( '192.168.147.128:9092' );
		// $config->setTopic( 'test' ); // 主题名称
		$config->setGroupId( 'default' ); // 分组ID
		// d(uniqid( '', false ));
		// $config->setClientId( uniqid( '', false ) ); // Kafka 客户端标识，不同的消费者进程请使用不同的设置
		// $config->setMemberId( uniqid( '', false ) );
		// $config->setGroupInstanceId(  ); // 分组实例 ID，不同的消费者进程请使用不同的设置
		//
		return $config;
	}

}
